var utils = require("../../utils/utils");
var appUtils = require("../../utils/app");
var ocrGml = require("../../utils/ocrGml");
var time = require("../../utils/time");
var inTask = require("./inTask");
var common = require("./common");
var Action = require("../../base/action");
var actionOpen2 = new Action("打开支付宝", {
  execSCount: 0,
  execFCount: 0,
  maxExecSCount: 1, //最大成功执行次数
  maxExecFCount: 2, //最大失败执行次数
  maxTotalExecCount: 3, //最大总执行次数
  storage: common.storage,
});
actionOpen2.exec = function () {
  var content = "去支付宝";
  var ocrItem = ocrGml.findTextOne(
    content,
    true,
    null,
    20,
    (device.height / 10) * 4
  );
  if (ocrItem) {
    utils.clickOcrItem(ocrItem);
    sleep(utils.getRandom(5, 8, 1000));
    if (appUtils.ifInstalled("支付宝")) {
      sleep(utils.getRandom(3, 5, 1000));
      appUtils.openApp("百度畅听版");
      sleep(utils.getRandom(2, 3, 1000));
    } else {
      sleep(utils.getRandom(3, 5, 1000));
      back();
    }
    inTask.run();
    this.execSCount++;
    this.updateStorage();
  } else {
    this.execFCount++;
    this.updateStorage();
    console.log("没有找到" + content);
  }
};
module.exports = actionOpen2;
